package com.ayi.servlet.backstage; /**
 * @author Ayingzz
 * @create 2021/12/6 8:49
 */

import com.ayi.bean.Book;
import com.ayi.dao.bookdao.AddBook;
import com.ayi.dao.bookdao.UpdateBook;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "editBookFromBooksServlet", value = "/editBookFromBooksServlet")
public class editBookFromBooksServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        int bookid = Integer.parseInt(request.getParameter("bookid"));
        String bookname = request.getParameter("bookname");
        String bookauthor = request.getParameter("bookauthor");
        String booktype = request.getParameter("booktype");
        double bookprice = Double.parseDouble(request.getParameter("bookprice"));
        int bookinventory = Integer.parseInt(request.getParameter("bookinventory"));
        String bookdetails = request.getParameter("bookdetails");

        Book book = new Book(bookid, bookname, bookauthor, booktype, bookdetails, bookprice, bookinventory);

        if (new UpdateBook().updateBookFromBooksById(book)) {
            response.sendRedirect("BackStageServlet");
        } else {

        }

    }
}
